package category;

import java.util.LinkedList;

import database.CategoryManager;

public class CategoryCore {
	
	CategoryCollection catCollection;
	
	//COSTRUTTORE
	
	public CategoryCore() {
		super();
		catCollection=CategoryManager.loadCategories();
	}
	
	//METODI
	
	public void addCategory(){
		CategoryCollectionInfo info=createCollectionInfo();
		//lanciare l'interfaccia passandogli "info"
	}

	private CategoryCollectionInfo createCollectionInfo() {
		CategoryCollectionInfo info=new CategoryCollectionInfo();
		for (String cat : catCollection.getCategoryList().keySet()){
			info.addCategory(cat);
		}
		return info;
	}
	
	public void addCategoryToDb(CategoryInfo ci){
		Category father=catCollection.getCategoryList().get(ci.getFather());
		LinkedList<Category> subCat=new LinkedList<Category>();
		for (String scat : ci.getSubcategories()){
			subCat.add(catCollection.getCategoryList().get(scat));
		}
		Category newCat=new Category(ci.getName());
		newCat.setFather(father);
		newCat.setSubCategories(subCat);
		
		CategoryManager.insertCategory(newCat);
		catCollection=CategoryManager.loadCategories();
	}
	
	
}
